<? include("include/mysql.config.php") ?>
<?
$action=$_GET['ac'];
if($action=='login'){
    $name=$_POST['name'];
    $pass=$_POST['pass'];
    $checkcode=$_POST["check"];
    $check=$_SESSION['randstr'];
    $error=array();
    if($name==null){
        $error[]='用户不能为空';
    }
    if($pass==null){
        $error[]='密码不能为空';
    }
    if($check==null){
        $error[]='验证码不能为空';
    }
    else{
        if($check!=$checkcode){
        
            $error[]='验证码码不正确';
        
        }
    }

    if(count($error)==0){
        if($name!=null&&$pass!=null){
            $pass=md5($pass);
            $sql="select * from admin where admin_name='$name' and admin_password='$pass'";
            $time1=microtime();
            $result=mysql_query($sql,$conn);
            if($result){
                if(mysql_num_rows($result)==1){
                    $_SESSION["admin_name"]=$name;           
                    $_SESSION["admin_pass"]=$pass;           
                    header("Location:admin.php");
                }
                else{
                $error[]='账号密码错误';
                }
            }
            else
            {
            $error[]='账号密码错误';
            }
        }
    }
    
}
if('loginout'==$action){
        unset($_SESSION["admin_name"]);
        unset($_SESSION["admin_pass"]);
        header("Location:login.php");


}
?>
<!DOCTYPE html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>登陆</title>
    <link href="asset/admin.css" rel="stylesheet" type="text/css">
    <script src="asset/jquery-1.6.4.min.js" ></script>
    <script src="asset/jquery.validate.min.js" ></script>
<script>
$(function(){
    $("#form1").validate({
		rules: {
			name: "required",
			pass: {
				required: true,
				minlength: 5
			},
			check: {
				required: true,
				minlength: 5,
			}
		},
		messages: {
			name: "请输入账号",
			pass: {
				required: "请输入密码",
				minlength: "密码最小为5位"
			},
			check: {
				required: "请输入验证码",
				minlength: "验证码最小为5位",
			}
		}
	});
});
</script>
</head>
<body>
    <form action="login.php?ac=login" id="form1" name="form1" method="post">
    <div class="error">
    <?
    for($i=0;$i<count($error);$i++){
        echo "<li>";
        echo $error[$i];
        echo "</li>";
    }

    ?>
    </div>
    <fieldset>
        <legend>登陆</legend>
        
       <p><label for="name">登陆名</label> <input id="name" name="name" type="text" /></p>
       <p><label for="pass">密　码</label> <input name="pass" type="password" /></p>
       <p><label for="">验证码</label><img style="vertical-align:top;" src="include/identifiying.php" > <input name="check" type="text" /></p>
       <p><input type="submit" value="登陆" /></p>
        
    </fieldset>
    </form>
</body>
</head>

